package com.example.DownloadImageHelper;

import java.io.File;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Environment;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.example.DownloadImageHelperLibrary.DownloadImageTask;
import android.app.Activity;
import android.os.Bundle;

public class MyActivity extends Activity {
    /**
     * Called when the activity is first created.
     *
     */
    Button btn1;
    Button btn2;
    Button btn3;
    Button btnReset;

    Button btnNotify;

    ImageView img;
    ProgressBar progressBar;
    TextView textView;

    String url = "http://www.thebiblescholar.com/android_awesome.jpg";
    File folder = new File(Environment.getExternalStorageDirectory() +  "/" + Environment.DIRECTORY_PICTURES);

    Context context;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        this.context = this;

        btn1 = (Button)findViewById(R.id.button1);
        btn2 = (Button)findViewById(R.id.button2);
        btn3 = (Button)findViewById(R.id.button3);
        btnReset = (Button)findViewById(R.id.btnReset);
        btnNotify = (Button)findViewById(R.id.buttonNotify);
        img = (ImageView)findViewById(R.id.imageView);
        progressBar = (ProgressBar)findViewById(R.id.progressBar);
        //progressBar.setIndeterminate(true);

        textView = (TextView)findViewById(R.id.textView);

        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new DownloadImageTask(img,folder,"imagedemo").execute(url);
            }
        });

        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {

                    }
                },5000);
                new DownloadImageTask(img,progressBar,folder,"imagedemo").execute(url);
            }
        });

        btn3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new DownloadImageTask(img,progressBar,textView,folder,"imagedemo").execute(url);
            }
        });

        btnReset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                img.setImageBitmap(null);
                img.setBackgroundColor(Color.WHITE);
            }
        });

        btnNotify.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context,NotifyAdapterActivity.class);
                startActivity(intent);
            }
        });
    }
}
